package com.swxc.smartorder.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swxc.smartorder.R;
import com.swxc.smartorder.utils.ImageDisplayUtil;

import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import it.sephiroth.android.library.imagezoom.ImageViewTouchBase;

/**
 * Author   Administrator
 * Date     2018/4/13
 * Desc     eg
 *
 * @author Administrator
 */
public class PreviewFragment extends Fragment {

    private static final String ARGS_ITEM = "args_item";

    public static PreviewFragment newInstance(String item) {
        PreviewFragment fragment = new PreviewFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ARGS_ITEM, item);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_preview, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        final String item = getArguments().getString(ARGS_ITEM);
        if (item == null) {
            return;
        }


        ImageViewTouch image = view.findViewById(com.zhihu.matisse.R.id.image_view);
        image.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);

        ImageDisplayUtil.showImageView(this.getContext(), item, image);

    }

    public void resetView() {
        if (getView() != null) {
            ((ImageViewTouch) getView().findViewById(R.id.image_view)).resetMatrix();
        }
    }
}
